<template>
	<view class="user-label">
		<view class="user-label-tit">
			<view>为了让我们更好服务您</view>
			<view>请选择一个身份标签！</view>
		</view>
		<view class="user-label-list">
			<view class="user-label-item" v-for="(data,index) in labelList" :key="index" :class="{active: activeIndex==index}" @click="choseLabel(index)">
				{{data.label_name}}
				<view class="check-box">
					<u-icon name="checkbox-mark" size="24" color="#F59359" v-if="activeIndex==index"></u-icon>
				</view>
			</view>
		</view>
		<view class="user-label-btn">
			<view @click="$u.throttle(submit,2000)" v-if="!is_submit">确定</view>
			<view class="is_submit" v-else> <u-loading mode="flower"></u-loading> 正在提交</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				labelList: [],
				activeIndex: -1,
				is_submit: false
			};
		},
		onLoad() {
			this.init()
		},
		methods: {
			init(){
				this.$u.api.GetUserLabel().then(res => {
					this.labelList = res.datas
				})
			},
			choseLabel(index){
				this.activeIndex = index
			},
			submit(){
				if(this.activeIndex==-1){
					uni.showToast({
						icon: 'none',
						title: '请选择一个身份标签'
					})
					return false
				}
				this.is_submit = true
				this.$u.api.UpLabel({role_label: this.labelList[this.activeIndex].role_label}).then(res => {
					this.is_submit = false
					uni.showToast({
						icon: 'none',
						title: '设置成功',
						duration: 1500
					})
					setTimeout(() => {
						uni.switchTab({
							url: '/pages/index/index'
						})
					},1500)
				}).catch(() => {
					this.is_submit = false
					uni.switchTab({
						url: '/pages/index/index'
					})
				})
			}
		}
	}
</script>

<style lang="scss">
	.user-label{
		padding-bottom: 140rpx;
		.user-label-tit{
			padding: 60rpx 55rpx 0;
			font-size: 36rpx;
			color: #141414;
			font-weight: bold;
			line-height: 60rpx;
		}
		.user-label-list{
			padding: 0 55rpx;
			.user-label-item{
				margin-top: 35rpx;
				height: 110rpx;
				background-color: #F7F7F7;
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 0 30rpx;
				font-size: 32rpx;
				color: #141414;
				font-weight: bold;
				border-radius: 8rpx;
				transition: all .5s;
				.check-box{
					border: solid 4rpx #CCC;
					width: 36rpx;
					height: 36rpx;
					border-radius: 4rpx;
					display: flex;
					align-items: center;
					justify-content: center;
				}
				&.active{
					background-color: #F59359;
					color: #FFF;
					.check-box{
						border-color: #FFF;
						background-color: #FFF;
					}
				}
			}
		}
		.user-label-btn{
			position: fixed;
			bottom: 0;
			background-color: #FFF;
			left: 0;
			right: 0;
			text-align: center;
			height: 120rpx;
			view{
				display: inline-block;
				width: 600rpx;
				height: 90rpx;
				line-height: 90rpx;
				background-color: #141414;
				border-radius: 8rpx;
				color: #FFF;
				font-size: 32rpx;
				margin-top: 15rpx;
				&.is_submit{
					opacity: .5;
					/deep/ .u-loading{
						margin-top: 0;
						margin-right: 10rpx;
					}
				}
			}
		}
	}
</style>